/*
 * Copyright (c) 2010-2013 Ruben Chakhmakhchyan. All rights reserved.
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Eclipse Public License
 * Version 1.0 (the 'License'). You may not use this file except in
 * compliance with the License. Please obtain a copy of the License at
 * http://opensource.org/licenses/EPL-1.0 and read it before using this file.
 */

#pragma once


#include "commontypes.h"
#include "wiacommon.h"
#include "image_site.h"


class CWiaDataCallback : public IWiaDataCallback
{
public:

	CWiaDataCallback( ImageSite* pImageSite, PFNPROGRESSCALLBACK pfnProgressCallback, PVOID pProgressCallbackParam, LONG* plCount );

	// IUnknown interface implementation
	STDMETHOD(QueryInterface)(REFIID iid, LPVOID *ppvObj);
	STDMETHOD_(ULONG, AddRef)();
	STDMETHOD_(ULONG, Release)();

	// IWiaDataCallback interface implementation
	STDMETHOD(BandedDataCallback)( LONG lMessage, LONG lStatus, LONG lPercentComplete, LONG lOffset, LONG lLength, LONG lReserved, LONG lResLength, BYTE* pbBuffer );

private:

	// Increases the size of the current stream object, or creates a new stream object if this is the first call.
	bool reallocBuffer( uint_t size );
	// Copies new data to the current stream.
	bool copyToBuffer( uint_t offset, const void* pBuffer, uint_t size );
	// Stores the current stream in the array of successfully transferred images.
	//bool storeBuffer();

private:

	LONG m_refCount;

	bool m_isBmp;
	LONG m_headerSize;
	LONG m_dataSize;
	uint_t m_imageSize;
	
	PFNPROGRESSCALLBACK m_pfnProgressCallback;
	PVOID m_pProgressCallbackParam;

	LONG *m_plCount;
	byte_t* m_pBuffer;

	ImageSite* m_pImageSite;
};
